package com.cskaoyan.service.wx;

import com.cskaoyan.bean.Order;
import com.cskaoyan.bean.OrderExample;
import com.cskaoyan.bean.User;
import com.cskaoyan.bean.UserExample;
import com.cskaoyan.bean.wxbean.OrderStatusBean;
import com.cskaoyan.mapper.OrderMapper;
import com.cskaoyan.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Enzo Cotter on 2020/10/7.
 */
@Service
public class WxUserServiceImpl implements WxUserService{
    @Autowired
    UserMapper userMapper;
    @Autowired
    OrderMapper orderMapper;
    @Override
    public OrderStatusBean selectOrderStatus(Integer id) {
        // 订单状态 1xx  为待付款  2xx 为代发货 3xx 为待收货 4xx 为待评价
        OrderExample orderExample = new OrderExample();
        OrderExample.Criteria criteriaOrder = orderExample.createCriteria();
        criteriaOrder.andUserIdEqualTo(id);
        List<Order> orders = orderMapper.selectByExample(orderExample);
        //待收货
        int unrecv = 0;
        // 待评价
        int uncomment = 0;
        // 待付款
        int unpaid = 0;
        // 待发货
        int unship = 0;

        for (Order order : orders) {
            if(String.valueOf(order.getOrderStatus()).equals("101")){
                unpaid++;
            } else if(String.valueOf(order.getOrderStatus()).equals("201")){
                unship++;
            } else if(String.valueOf(order.getOrderStatus()).equals("301")){
                unrecv++;
            } else if(String.valueOf(order.getOrderStatus()).equals("401")){
                uncomment++;
            }
        }
        OrderStatusBean orderStatusBean = new OrderStatusBean(unrecv,uncomment,unpaid,unship);

        return orderStatusBean;
    }
}
